﻿namespace WMS6.Web.Outbound
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.OutboundDetailServiceRef;
    using WMS6.Web.OutboundServiceRef;

    public class WaveDetail2 : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected Button btnSaveContinue;
        protected Button btnSearch;
        protected HtmlForm F7194;
        protected GridView gvWaveDetail;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnWaveID;
        protected HtmlHead Head1;
        protected HtmlImage imgOrderID;
        protected Label Label1;
        protected Label Label2;
        protected Label lbl;
        protected Label lblBatchOrderDetail;
        protected Label lblCarrierIdEnd;
        protected Label lblCarrierIdStart;
        protected Label lblCityBegin;
        protected Label lblCityEnd;
        protected Label lblCompanyEnd;
        protected Label lblCompanyStart;
        protected Label lblDeliveryDataEnd;
        protected Label lblDeliveryDataStart;
        protected Label lblDescr;
        protected Label lblDoorEnd;
        protected Label lblDoorStart;
        protected Label lblExternOrderIdEnd;
        protected Label lblExternOrderIdStart;
        protected Label lblFrom;
        protected Label lblLoadIdEnd;
        protected Label lblLoadIdStart;
        protected Label lblLotEnd;
        protected Label lblLotStart;
        protected Label lblMsg;
        protected Label lblOrderDateEnd;
        protected Label lblOrderDateStart;
        protected Label lblOrderIdEnd;
        protected Label lblOrderIdStart;
        protected Label lblOrderPriorityEnd;
        protected Label lblOrderPriorityStart;
        protected Label lblOrderStatusEnd;
        protected Label lblOrderStatusStart;
        protected Label lblOrderTypeEnd;
        protected Label lblOrderTypeStart;
        protected Label lblOwnerIdEnd;
        protected Label lblOwnerIdStart;
        protected Label lblRouteEnd;
        protected Label lblRouteStart;
        protected Label lblSkuClassIdEnd;
        protected Label lblSkuClassIdStart;
        protected Label lblSkuIdEnd;
        protected Label lblSkuIdStart;
        protected Label lblStopEnd;
        protected Label lblStopStart;
        protected Label lblTo;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected ScriptManager ScriptManager1;
        protected TextBox txtCarrierIdEnd;
        protected TextBox txtCarrierIdStart;
        protected TextBox txtCityEnd;
        protected TextBox txtCityStart;
        protected TextBox txtCompanyEnd;
        protected TextBox txtCompanyStart;
        protected TextBox txtDeliveryDataEnd;
        protected TextBox txtDeliveryDataStart;
        protected TextBox txtDescr;
        protected TextBox txtDoorEnd;
        protected TextBox txtDoorStart;
        protected TextBox txtExternOrderIdEnd;
        protected TextBox txtExternOrderIdStart;
        protected TextBox txtLoadIdEnd;
        protected TextBox txtLoadIdStart;
        protected TextBox txtLotEnd;
        protected TextBox txtLotStart;
        protected TextBox txtOrderDateEnd;
        protected TextBox txtOrderDateStart;
        protected TextBox txtOrderIdEnd;
        protected TextBox txtOrderIdStart;
        protected TextBox txtOrderPriorityEnd;
        protected TextBox txtOrderPriorityStart;
        protected TextBox txtOrderSelectionID;
        protected TextBox txtOrderStatusEnd;
        protected TextBox txtOrderStatusStart;
        protected TextBox txtOrderTypeEnd;
        protected TextBox txtOrderTypeStart;
        protected TextBox txtOwnerIdEnd;
        protected TextBox txtOwnerIdStart;
        protected TextBox txtRouteEnd;
        protected TextBox txtRouteStart;
        protected TextBox txtSkuClassIdEnd;
        protected TextBox txtSkuClassIdStart;
        protected TextBox txtSkuIdEnd;
        protected TextBox txtSkuIdStart;
        protected TextBox txtStopEnd;
        protected TextBox txtStopStart;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(string.Format("Wave.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnWaveID.Value.Trim())));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            List<string> selectedID = base.GetSelectedIDsInGridView(this.gvWaveDetail, "ORDER_ID");
            List<string> selecteStatus = base.GetSelectedIDsInGridView(this.gvWaveDetail, "STATUS");
            if (selectedID.Count > 0)
            {
                try
                {
                    WMS6.Web.OutboundDetailServiceRef.WaveDetailInfo waveDetail = new WMS6.Web.OutboundDetailServiceRef.WaveDetailInfo {
                        WaveID = this.hdnWaveID.Value,
                        OrderID = "",
                        ProcessStatus = "",
                        CreatedBy = base.UserInfo.UserID
                    };
                    this.lblMsg.Text = OutboundDetailServiceClientProxy.GetInstance().SaveWavebyOrderSelection(waveDetail, selectedID, selecteStatus) + base.GetGlobalMsgResource("F7300_008");
                    base.Response.Redirect(string.Format("Wave.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnWaveID.Value)));
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                    this.lblMsg.Visible = true;
                }
            }
            else
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F7300_015");
                this.lblMsg.Visible = true;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);</script>", false);
            }
        }

        protected void btnSaveContinue_Click(object sender, EventArgs e)
        {
            List<string> selectedID = base.GetSelectedIDsInGridView(this.gvWaveDetail, "ORDER_ID");
            List<string> selecteStatus = base.GetSelectedIDsInGridView(this.gvWaveDetail, "STATUS");
            if (selectedID.Count > 0)
            {
                try
                {
                    WMS6.Web.OutboundDetailServiceRef.WaveDetailInfo waveDetail = new WMS6.Web.OutboundDetailServiceRef.WaveDetailInfo {
                        WaveID = this.hdnWaveID.Value,
                        OrderID = "",
                        ProcessStatus = "",
                        CreatedBy = base.UserInfo.UserID
                    };
                    this.lblMsg.Text = OutboundDetailServiceClientProxy.GetInstance().SaveWavebyOrderSelection(waveDetail, selectedID, selecteStatus) + base.GetGlobalMsgResource("F7300_008");
                    this.txtOrderSelectionID.Text = "";
                    this.gvWaveDetail.DataSource = null;
                    this.gvWaveDetail.DataBind();
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                    this.lblMsg.Visible = true;
                }
            }
            else
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F7300_015");
                this.lblMsg.Visible = true;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);</script>", false);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            DataSet ds = null;
            Exception ex;
            try
            {
                OrderSelectionInfo orderSelection = new OrderSelectionInfo {
                    OrderSelectionID = this.txtOrderSelectionID.Text,
                    Descr = this.txtDescr.Text,
                    OrderIdStart = this.txtOrderIdStart.Text,
                    OrderIdEnd = this.txtOrderIdEnd.Text,
                    OwnerIdStart = this.txtOwnerIdStart.Text,
                    OwnerIdEnd = this.txtOwnerIdEnd.Text,
                    OrderStatusStart = this.txtOrderStatusStart.Text,
                    OrderStatusEnd = this.txtOrderStatusEnd.Text,
                    OrderTypeStart = this.txtOrderTypeStart.Text,
                    OrderTypeEnd = this.txtOrderTypeEnd.Text
                };
                try
                {
                    if (!string.IsNullOrEmpty(this.txtOrderDateStart.Text))
                    {
                        orderSelection.OrderDateStart = DateTime.Parse(this.txtOrderDateStart.Text);
                    }
                    if (!string.IsNullOrEmpty(this.txtOrderDateEnd.Text))
                    {
                        orderSelection.OrderDateEnd = DateTime.Parse(this.txtOrderDateEnd.Text);
                    }
                    if (!string.IsNullOrEmpty(this.txtDeliveryDataStart.Text))
                    {
                        orderSelection.DeliveryDateStart = DateTime.Parse(this.txtDeliveryDataStart.Text);
                    }
                    if (!string.IsNullOrEmpty(this.txtDeliveryDataEnd.Text))
                    {
                        orderSelection.DeliveryDateEnd = DateTime.Parse(this.txtDeliveryDataEnd.Text);
                    }
                }
                catch (Exception exception1)
                {
                    ex = exception1;
                    throw new Exception("请输入正确的日期!");
                }
                orderSelection.ExternOrderIdStart = this.txtExternOrderIdStart.Text;
                orderSelection.ExternOrderIdEnd = this.txtExternOrderIdEnd.Text;
                orderSelection.OrderPriorityStart = this.txtOrderPriorityStart.Text;
                orderSelection.OrderPriorityEnd = this.txtOrderPriorityEnd.Text;
                orderSelection.CompanyStart = this.txtCompanyStart.Text;
                orderSelection.CompanyEnd = this.txtCompanyEnd.Text;
                orderSelection.CityBegin = this.txtCityStart.Text;
                orderSelection.CityEnd = this.txtCityEnd.Text;
                orderSelection.CarrierIdStart = this.txtCarrierIdStart.Text;
                orderSelection.CarrierIdEnd = this.txtCarrierIdEnd.Text;
                orderSelection.DoorStart = this.txtDoorStart.Text;
                orderSelection.DoorEnd = this.txtDoorStart.Text;
                orderSelection.RouteStart = this.txtRouteStart.Text;
                orderSelection.RouteEnd = this.txtRouteEnd.Text;
                orderSelection.StopStart = this.txtStopStart.Text;
                orderSelection.StopEnd = this.txtStopEnd.Text;
                orderSelection.LoadIdStart = this.txtLoadIdStart.Text;
                orderSelection.LoadIdEnd = this.txtLoadIdEnd.Text;
                orderSelection.SkuIdStart = this.txtSkuIdStart.Text;
                orderSelection.SkuIdEnd = this.txtSkuIdEnd.Text;
                orderSelection.LotStart = this.txtLotStart.Text;
                orderSelection.LotEnd = this.txtLotEnd.Text;
                orderSelection.SkuClassIdStart = this.txtSkuClassIdStart.Text;
                orderSelection.SkuClassIdEnd = this.txtSkuClassIdEnd.Text;
                orderSelection.Descr = this.txtDescr.Text;
                ds = OutboundServiceClientProxy.GetInstance().GetOrdersByOrderSelection(orderSelection);
                base.DataEntityViewState = ds;
                if ((ds != null) && (ds.Tables.Count > 0))
                {
                    base.BindData2GridView1(this.gvWaveDetail, ds);
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7300_020");
                    this.lblMsg.Visible = true;
                }
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);</script>", false);
            }
            catch (Exception exception2)
            {
                ex = exception2;
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void gvWaveDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F7164", this.gvWaveDetail);
        }

        protected void gvWaveDetail_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = base.DataEntityViewState as DataSet;
            (sender as GridView).DataBind();
        }

        protected void gvWaveDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.hdnFrom.Value = base.Request.QueryString["from"];
                this.hdnWaveID.Value = base.Request.QueryString["ID"];
                string strDate = base.GetValueFromAppSettings("ORDER_SELECTION_ADVANCE_STARTDATE");
                if (!string.IsNullOrEmpty(strDate))
                {
                    if (strDate != "0")
                    {
                        this.txtOrderDateStart.Text = base.GetPreferenceShortDate(DateTime.Now.AddDays(double.Parse(strDate) * -1.0));
                        this.txtDeliveryDataStart.Text = base.GetPreferenceShortDate(DateTime.Now.AddDays(double.Parse(strDate) * -1.0));
                        this.txtOrderDateEnd.Text = base.GetPreferenceShortDate(DateTime.Now);
                        this.txtDeliveryDataEnd.Text = base.GetPreferenceShortDate(DateTime.Now);
                    }
                    else
                    {
                        this.txtOrderDateStart.Text = "";
                        this.txtDeliveryDataStart.Text = "";
                        this.txtOrderDateEnd.Text = "";
                        this.txtDeliveryDataEnd.Text = "";
                    }
                }
                else
                {
                    this.txtOrderDateStart.Text = "";
                    this.txtDeliveryDataStart.Text = "";
                    this.txtOrderDateEnd.Text = "";
                    this.txtDeliveryDataEnd.Text = "";
                }
            }
        }

        protected void txtOrderSelectionID_OnTextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtOrderSelectionID.Text))
            {
                OrderSelectionInfo orderSelection = OutboundServiceClientProxy.GetInstance().GetOrderSelectionByID(this.txtOrderSelectionID.Text);
                if (orderSelection != null)
                {
                    this.txtDescr.Text = orderSelection.Descr;
                    this.txtOrderIdStart.Text = orderSelection.OrderIdStart;
                    this.txtOrderIdEnd.Text = orderSelection.OrderIdEnd;
                    this.txtOwnerIdStart.Text = orderSelection.OwnerIdStart;
                    this.txtOwnerIdEnd.Text = orderSelection.OwnerIdEnd;
                    this.txtOrderStatusStart.Text = orderSelection.OrderStatusStart;
                    this.txtOrderStatusEnd.Text = orderSelection.OrderStatusEnd;
                    this.txtOrderTypeStart.Text = orderSelection.OrderTypeStart;
                    this.txtOrderTypeEnd.Text = orderSelection.OrderTypeEnd;
                    this.txtOrderDateStart.Text = base.GetPreferenceShortDate(orderSelection.OrderDateStart);
                    this.txtOrderDateEnd.Text = base.GetPreferenceShortDate(orderSelection.OrderDateEnd);
                    this.txtDeliveryDataStart.Text = base.GetPreferenceShortDate(orderSelection.DeliveryDateStart);
                    this.txtDeliveryDataEnd.Text = base.GetPreferenceShortDate(orderSelection.DeliveryDateEnd);
                    this.txtExternOrderIdStart.Text = orderSelection.ExternOrderIdStart;
                    this.txtExternOrderIdEnd.Text = orderSelection.ExternOrderIdEnd;
                    this.txtOrderPriorityStart.Text = orderSelection.OrderPriorityStart;
                    this.txtOrderPriorityEnd.Text = orderSelection.OrderPriorityEnd;
                    this.txtCompanyStart.Text = orderSelection.CompanyStart;
                    this.txtCompanyEnd.Text = orderSelection.CompanyEnd;
                    this.txtCityStart.Text = orderSelection.CityBegin;
                    this.txtCityEnd.Text = orderSelection.CityEnd;
                    this.txtCarrierIdStart.Text = orderSelection.CarrierIdStart;
                    this.txtCarrierIdEnd.Text = orderSelection.CarrierIdEnd;
                    this.txtDoorStart.Text = orderSelection.DoorStart;
                    this.txtDoorStart.Text = orderSelection.DoorEnd;
                    this.txtRouteStart.Text = orderSelection.RouteStart;
                    this.txtRouteEnd.Text = orderSelection.RouteEnd;
                    this.txtStopStart.Text = orderSelection.StopStart;
                    this.txtStopEnd.Text = orderSelection.StopEnd;
                    this.txtLoadIdStart.Text = orderSelection.LoadIdStart;
                    this.txtLoadIdEnd.Text = orderSelection.LoadIdEnd;
                    this.txtSkuIdStart.Text = orderSelection.SkuIdStart;
                    this.txtSkuIdEnd.Text = orderSelection.SkuIdEnd;
                    this.txtLotStart.Text = orderSelection.LotStart;
                    this.txtLotEnd.Text = orderSelection.LotEnd;
                    this.txtSkuClassIdStart.Text = orderSelection.SkuClassIdStart;
                    this.txtSkuClassIdEnd.Text = orderSelection.SkuClassIdEnd;
                }
            }
        }
    }
}

